package aar.test.tessocr.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import aar.test.tessocr.CabinetDetailsActivity;
import aar.test.tessocr.baseApplication.BaseApplication;
import aar.test.tessocr.model.CabinetListMpdel;
import clx.tessocr.ocreng.R;

/**
 * Created by 149-201605 on 2016/8/1.
 */

/*
* 主界面显示 dialog的资源适配器
* */
public class PieListAdapter extends BaseAdapter {

    private List<CabinetListMpdel> mList;

    private Context mContext;



    public PieListAdapter(Context mContext, List<CabinetListMpdel> mList) {
        this.mList = mList;
        this.mContext = mContext;


    }



    @Override
    public int getCount() {
        int count = 0;
        if (null != mList && !mList.isEmpty()) {
            count = mList.size();
        }
        return count;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder showDialogHolder = null;
        if (null == convertView) {
            showDialogHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.cabinet_list_item, null);
            showDialogHolder.title = (TextView) convertView.findViewById(R.id.title);
            showDialogHolder.title_address = (TextView) convertView.findViewById(R.id.title_address);
            showDialogHolder.title_details = (TextView) convertView.findViewById(R.id.title_details);
            convertView.setTag(showDialogHolder);
        } else {
            showDialogHolder = (ViewHolder) convertView.getTag();
        }

        final CabinetListMpdel cabinetListMpdel;
        cabinetListMpdel=mList.get(position);

        showDialogHolder.title.setText(mList.get(position).getCabinetname());
        showDialogHolder.title_address.setText(mList.get(position).getAddress());
        showDialogHolder.title_details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseApplication.getIntance().setCabinetListMpdel(cabinetListMpdel);
                mContext.startActivity(new Intent(mContext, CabinetDetailsActivity.class));
            }
        });






        return convertView;
    }


    class ViewHolder {
        TextView title;
        TextView title_address;
        TextView title_details;
    }
}


